package com.sesame;

import com.github.kevinsawicki.http.HttpRequest;
import kim.sesame.common.utils.ImgBase64;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class Test {

    static String url = "http://127.0.0.1:8072/api/upload";

    public static void main(String[] args) {
        uploadFile();
//        uploadBase64();
    }

    public static void uploadFile() {
        File input = new File("/Users/wjh/images/111.jpg");

        HttpRequest request = HttpRequest.post(url);
        request.part("file", input.getName(), "multipart/form-data;", input);
        request.part("module", "fms/user");
        String result = request.body();

        System.out.println(result);
    }

    public static void uploadBase64() {
        String file = "/Users/wjh/images/111.jpg";
        String base64 = ImgBase64.conversionString(file);

        Map<String, String> map = new HashMap<>();
        map.put("module", "fms/user");
        map.put("fileBase64", base64);
        map.put("fileType", ".jpg");

        String result = HttpRequest.post(url)
                .form(map).body();

        System.out.println(result);
    }
}
